<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>签收单模版</title>
  <style>
    :root {
      --primary-color: #4361ee;
      --secondary-color: #3a0ca3;
      --accent-color: #7209b7;
      --light-color: #f8f9fa;
      --dark-color: #212529;
      --success-color: #4bb543;
      --border-color: #dee2e6;
      --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    
    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background-color: #fff;
      margin: 0;
      padding: 20px;
      color: var(--dark-color);
    }

    .container {
      background-color: white;
      border-radius: 12px;
      box-shadow: var(--shadow);
      padding: 30px;
      margin: 0 auto;
      max-width: 1000px;
      position: relative;
      overflow: hidden;
      margin-top: 20px;
    }

    h1 {
      font-size: 28px;
      font-weight: 700;
      text-align: center;
      margin: 0 0 25px;
      padding-bottom: 15px;
      border-bottom: 2px solid var(--border-color);
      position: relative;
    }

    .header-info {
      display: flex;
      flex-wrap: wrap;
      gap: 30px;
      margin-bottom: 30px;
      background: #f8f9fa;
      padding: 20px;
      border-radius: 8px;
    }

    .header-info div {
      flex: 1;
      min-width: 300px;
    }

    .header-info p {
      margin: 12px 0;
      line-height: 1.6;
      display: flex;
    }

    .header-info strong {
      width: 80px;
      display: inline-block;
      color: var(--secondary-color);
    }

    .header-info span {
      flex: 1;
      padding: 5px 10px;
      border-bottom: 1px dashed #ccc;
      min-height: 24px;
    }

    .button-container {
      position: fixed;
      top: 50%;
      right: 20px;
      transform: translateY(-50%);
      display: flex;
      flex-direction: column;
      gap: 15px;
      z-index: 100;
    }

    .download-btn {
      background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
      color: white;
      padding: 12px 24px;
      border-radius: 50px;
      font-weight: 600;
      transition: all 0.3s ease;
      box-shadow: var(--shadow);
      border: none;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 15px;
    }

    .download-btn:hover {
      transform: translateY(-3px);
      box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    }

    .download-btn i {
      font-size: 18px;
    }

    table {
      width: 100%;
      border-collapse: collapse;
      margin-bottom: 30px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
      border-radius: 8px;
      overflow: hidden;
    }

    th, td {
      border: 1px solid var(--border-color);
      padding: 12px 15px;
      text-align: center;
    }

    th {
      background-color: var(--primary-color);
      color: white;
      font-weight: 600;
      text-align: center;
    }

    tr:nth-child(even) {
      background-color: #f8f9fa;
    }

    tr:hover {
      background-color: #e9ecef;
    }

    .total-row {
      font-weight: 700;
      background-color: #e6f7ff !important;
    }

    .total-row td {
      color: var(--secondary-color);
    }

    [contenteditable="true"] {
      padding: 5px 8px;
      border-radius: 4px;
      transition: all 0.2s;
    }

    [contenteditable="true"]:focus {
      outline: none;
      background-color: #fff8e1;
      box-shadow: inset 0 0 0 2px #ffecb3;
    }

    .signature-area {
      display: flex;
      flex-wrap: wrap;
      gap: 40px;
      margin-top: 40px;
    }

    .signature-box {
      flex: 1;
      min-width: 300px;
    }

    .signature-box p {
      font-weight: 600;
      color: var(--secondary-color);
      margin-bottom: 15px;
    }

    .signature-line {
      border-top: 1px solid var(--dark-color);
      margin-top: 50px;
      padding-top: 10px;
      position: relative;
    }

    .signature-line::before {
      content: "签字：";
      position: absolute;
      left: 0;
      top: -25px;
      font-size: 14px;
      color: #666;
    }

    .date-line {
      margin-top: 50px;
      position: relative;
      padding-top: 10px;
    }

    .date-line::before {
      content: "日期：";
      position: absolute;
      left: 0;
      top: -20px;
      font-size: 14px;
      color: #666;
    }

    .date-line::after {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      border-top: 1px solid var(--dark-color);
    }

    @media print {
      .button-container {
        display: none;
      }

      body {
        padding: 0;
        background-color: white;
      }

      .container {
        box-shadow: none;
        padding: 0;
      }

      .container::before {
        height: 5px;
      }
    }

    @media (max-width: 768px) {
      .container {
        padding: 20px;
      }
      
      .button-container {
        position: static;
        flex-direction: row;
        justify-content: center;
        margin: 20px 0;
        transform: none;
      }
      
      .header-info {
        gap: 15px;
        padding: 15px;
      }
    }
  </style>
  <link rel="stylesheet" href="../css/all.min.css">
</head>

<body>
  <div class="container">
    <h1 contenteditable="true">签收单</h1>

    <div class="button-container">
      <button class="download-btn" onclick="addRow()">
        <i class="fas fa-plus"></i> 添加货物
      </button>
      <button class="download-btn" onclick="printDocument()">
        <i class="fas fa-print"></i> 打印单据
      </button>
    </div>

    <div class="header-info">
      <div>
        <p><strong>送货单位：</strong><span contenteditable="true">XX有限公司</span></p>
        <p><strong>送货单号：</strong><span contenteditable="true">WL-2023-XXXXX</span></p>
        <p><strong>联系电话：</strong><span contenteditable="true">138-XXXX-XXXX</span></p>
      </div>
      <div>
        <p><strong>收货单位：</strong><span contenteditable="true">XX有限公司</span></p>
        <p><strong>收货地址：</strong><span contenteditable="true">XX市XX区XX路XX号</span></p>
        <p><strong>联系电话：</strong><span contenteditable="true">138-XXXX-XXXX</span></p>
      </div>
    </div>

    <table id="receipt-table">
      <thead>
        <tr>
          <th width="5%">序号</th>
          <th width="35%">货物名称</th>
          <th width="25%">规格型号</th>
          <th width="15%">单位</th>
          <th width="20%">数量</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td style="text-align: center;">1</td>
          <td contenteditable="true"></td>
          <td contenteditable="true"></td>
          <td contenteditable="true"></td>
          <td contenteditable="true" class="quantity-cell"></td>
        </tr>
        <tr class="total-row">
          <td colspan="3" style="text-align: center;">合计</td>
          <td></td>
          <td id="total-quantity">0</td>
        </tr>
      </tbody>
    </table>

    <div class="signature-area">
      <div class="signature-box">
        <p><i class="fas fa-truck"></i> 送货方确认：</p>
        <div class="signature-line"></div>
        <div class="date-line"></div>
      </div>
      <div class="signature-box">
        <p><i class="fas fa-box-open"></i> 收货方确认：</p>
        <div class="signature-line"></div>
        <div class="date-line"></div>
      </div>
    </div>
  </div>

  <script>
    // 打印文档
    function printDocument() {
      const buttons = document.querySelectorAll('.download-btn');
      buttons.forEach(button => button.style.display = 'none');

      window.print();

      setTimeout(() => {
        buttons.forEach(button => button.style.display = 'flex');
      }, 500);
    }

    // 添加新行
    function addRow() {
      const table = document.getElementById('receipt-table');
      const tbody = table.querySelector('tbody');
      const rows = tbody.querySelectorAll('tr');
      const newRow = tbody.insertBefore(document.createElement('tr'), rows[rows.length - 1]);

      // 序号列
      const cell1 = document.createElement('td');
      cell1.textContent = rows.length - 1;
      cell1.style.textAlign = 'center';
      newRow.appendChild(cell1);

      // 货物名称
      const cell2 = document.createElement('td');
      cell2.contentEditable = true;
      newRow.appendChild(cell2);

      // 规格型号
      const cell3 = document.createElement('td');
      cell3.contentEditable = true;
      newRow.appendChild(cell3);

      // 单位
      const cell4 = document.createElement('td');
      cell4.contentEditable = true;
      newRow.appendChild(cell4);

      // 数量
      const cell5 = document.createElement('td');
      cell5.contentEditable = true;
      cell5.className = 'quantity-cell';
      newRow.appendChild(cell5);

      // 添加输入事件监听
      cell5.addEventListener('input', updateTotal);

      // 更新所有序号
      updateRowNumbers();
    }

    // 更新行号
    function updateRowNumbers() {
      const rows = document.querySelectorAll('#receipt-table tbody tr:not(.total-row)');
      rows.forEach((row, index) => {
        row.cells[0].textContent = index + 1;
      });
    }

    // 更新合计
    function updateTotal() {
      const quantityCells = document.querySelectorAll('.quantity-cell:not(.total-row td)');
      let total = 0;
      
      quantityCells.forEach(cell => {
        const value = parseFloat(cell.textContent) || 0;
        total += value;
        
        // 实时格式化显示
        if (cell.textContent.trim() !== '') {
          cell.textContent = formatNumber(value);
        }
      });

      document.getElementById('total-quantity').textContent = formatNumber(total);
    }

    // 数字格式化
    function formatNumber(num) {
      // 如果是整数就不显示小数部分
      return num % 1 === 0 ? num.toString() : num.toFixed(2).replace(/\.?0+$/, '');
    }

    // 初始化事件监听
    document.addEventListener('DOMContentLoaded', function() {
      // 为现有的数量单元格添加事件监听
      document.querySelectorAll('.quantity-cell').forEach(cell => {
        cell.addEventListener('input', updateTotal);
      });
      
      // 初始计算
      updateTotal();
    });
  </script>
</body>

</html>